﻿using System;
using System.Collections.Generic;
using UnityEngine;

//管理一个技能的所有效果
public class SkillEffectController
{
	public SkillEffectVo vo;

	public GameObject caster;

	public GameObject[] targets;

	public float rootTime = 0;

	public List<SkillActionController> actionList = new List<SkillActionController>();

	public List<SkillActionController> cacheList = new List<SkillActionController>();

	public void Init(GameObject _caster,GameObject[] _targets,SkillEffectVo _vo){
		caster = _caster;
		targets = _targets;
		vo = _vo;
		rootTime = 0;

		foreach (SkillActionVo actionVo in vo.ActionList) {
			SkillActionController action = getSkillAction ();
			action.Init (actionVo);
			actionList.Add (action);
		}
	}

	private SkillActionController getSkillAction(){
		SkillActionController result = null;
		if (cacheList.Count > 0) {
			result = cacheList [0];
			cacheList.Remove (result);
		} else {
			result = new SkillActionController ();
		}
		result.effect = this;
		return result;
	}

	public void Update(){
		rootTime += Time.deltaTime;
		foreach (SkillActionController vo in actionList) {
			vo.Update ();
		}
	}

}

